package com.b2bpsssm.controller.sysmanage;/**
 * @author JunYu
 * @create 2022-08-14--14:27
 */

import com.b2bpsssm.common.R;
import com.b2bpsssm.ov.PrintTemplateInOV;
import com.b2bpsssm.simulate.GeneratePrintConfig;
import com.b2bpsssm.simulate.GeneratePrintTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: B2BPSSMSystem
 * @description: 打印模型控制器
 * @author: JunYu
 * @create: 2022-08-14 14:27
 **/
@Controller
@EnableSwagger2
@RequestMapping("/print_template")
@Api(value = "打印模板模块", tags = "打印模板模块api")
public class PrintTemplateController {
    //增加打印模板
    @RequestMapping(value = "/addPrintTemplate", method = RequestMethod.POST)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "增加打印模板", notes = "输入所需参数来增加打印模板", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "printTemplateInOV", value = "原型图对应参数", paramType = "Object", dataType = "json", required = true)
            }
    )
    public R addPrintModel(@RequestBody PrintTemplateInOV printTemplateInOV) {
        R r = new R();
        r.setCode(200);
        r.setMassage("添加成功，添加的模板名称为：" + printTemplateInOV.getName() + "添加的配置字段有：" + printTemplateInOV.getConfigIds());
        return r;
    }

    //删除模板
    @RequestMapping(value = "/delPrintTemplate", method = RequestMethod.POST)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "删除模板", notes = "通过模板id来删除模板", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "模板id", paramType = "int", dataType = "String", required = true)
            }
    )
    public R delPrintTemplate(@RequestParam("id") int id) {
        R r = new R();
        r.setCode(200);
        r.setMassage("删除成功，删除的模板id为：" + id);
        return r;
    }

    //修改模板
    @RequestMapping(value = "/updatePrintTemplate", method = RequestMethod.POST)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "修改模板", notes = "修改模板", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "printTemplateInOV", value = "原型图对应参数", paramType = "Object", dataType = "json", required = true)
            }
    )
    public R updatePrintTemplate(@RequestBody PrintTemplateInOV printTemplateInOV) {
        R r = new R();
        r.setCode(200);
        r.setMassage("编辑成功，编辑后的模板名称为：" + printTemplateInOV.getName() + "编辑后的配置字段有：" + printTemplateInOV.getConfigIds());
        return r;
    }

    //查询所有模板
    @RequestMapping(value = "/findTemplateList", method = RequestMethod.GET)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "查询所有模板", notes = "输入当前页码和页面长度来查询所有模板", httpMethod = "get", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "页码长度", paramType = "int", dataType = "String", required = true)
            }
    )
    public R findTemplateList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        R r = new R();
        r.setCode(200);
        r.setMassage("查询所有打印模板成功");
        r.setData(GeneratePrintTemplate.generatePrintTemplateList(pageSize));
        return r;
    }

    //根据模板名称查询模板
    @RequestMapping(value = "/findTemplateByName", method = RequestMethod.GET)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "根据模板名称查询模板", notes = "根据模板名称查询模板", httpMethod = "get", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "template_name", value = "模板名称", paramType = "String", dataType = "String", required = true)
            }
    )
    public R findTemplateByName(@RequestParam("template_name") String template_name) {
        R r = new R();
        r.setCode(200);
        r.setMassage("查询打印模板成功，查询的模板名字为：" + template_name);
        r.setData(GeneratePrintTemplate.generatePrintTemplate());
        return r;
    }

    //查询所有配置字段
    @RequestMapping(value = "/findConfigList", method = RequestMethod.GET)
    @ResponseBody
    //swagger配置
    @ApiOperation(value = "查询所有配置字段", notes = "查询所有配置字段，直接将配置字段全部查出，无需分页", httpMethod = "", response =R.class)
    public R findConfigList() {
        R r = new R();
        r.setCode(200);
        r.setMassage("查询所有打印模板成功");
        r.setData(GeneratePrintConfig.generateConfigList());
        return r;
    }
}
